import storage from '@/utils/storage'

export const state = {
  sortData: null,
	outboundData: null,
	labelData: null,
	moveData: null,
	selectData: null
}

export const mutations = {
	SET_SELECT_DATA: (state, value) => {
	  state.selectData = value
		storage.set('SELECT_DATA', value, 86400)
	},
	CLEAR_SELECT_DATA(state) {
		state.selectData = null
		storage.remove('SELECT_DATA')
	},
  SET_MOVE_DATA: (state, value) => {
    state.moveData = value
		storage.set('MOVE_DATA', value, 86400)
  },
	CLEAR_MOVE_DATA(state) {
		state.moveData = null
		storage.remove('MOVE_DATA')
	},
	SET_LABEL_DATA: (state, value) => {
    state.labelData = value
		storage.set('LABEL_DATA', value, 86400)
  },
	CLEAR_LABEL_DATA(state) {
		state.labelData = null
		storage.remove('LABEL_DATA')
	},
	SET_SORT_DATA: (state, value) => {
    state.sortData = value
		storage.set('SORT_DATA', value, 86400)
  },
	CLEAR_SORT_DATA(state) {
		state.sortData = null
		storage.remove('SORT_DATA')
	},
	SET_OUTBOUND_DATA: (state, value) => {
	  state.outboundData = value
		storage.set('OUTBOUND_DATA', value, 86400)
	},
	CLEAR_OUTBOUND_DATA(state) {
		state.outboundData = null
		storage.remove('OUTBOUND_DATA')
	}
}

export const getters = {
	getSelectData(state) {
	  if (state.selectData) {
	    return state.selectData
	  } else if (storage.get('SELECT_DATA')) {
	    return storage.get('SELECT_DATA')
	  }
	  return {}
	},
	getMoveData(state) {
	  if (state.moveData) {
	    return state.moveData
	  } else if (storage.get('MOVE_DATA')) {
	    return storage.get('MOVE_DATA')
	  }
	  return {}
	},
	getLabelData(state) {
	  if (state.labelData) {
	    return state.labelData
	  } else if (storage.get('LABEL_DATA')) {
	    return storage.get('LABEL_DATA')
	  }
	  return {}
	},
  getSortData(state) {
    if (state.sortData) {
      return state.sortData
    } else if (storage.get('SORT_DATA')) {
      return storage.get('SORT_DATA')
    }
    return {}
  },
	getOutboundData(state) {
		if (state.outboundData) {
			return state.outboundData
		} else if (storage.get('OUTBOUND_DATA')) {
			return storage.get('OUTBOUND_DATA')
		}
		return {}
	}
}
